#下面是dbshop的后台操作
import time

from public.publicOperation import BrowserObject, openUrl
from public.publicbusiness import menu2_operation, dbshop_bg_login, menu3_operation
from tool.tool import write_to_log

firefox=BrowserObject(1)  #调用自定义函数返回一个浏览器对象用firefox这个对象来接收
firefox.implicitly_wait(20)#隐式等待
openUrl('http://localhost/dbshop/admin',firefox) #调用自定义函数打开dbhsop的首页
dbshop_bg_login('admin','123456',firefox)
menu3_operation('商品管理','管理分类',"商品分类",firefox)
#点击添加分类按钮
firefox.find_element_by_link_text('添加分类').click()
#输入商品分类
firefox.find_element_by_id('class_name').send_keys('a01')
#清空默认 分类排序
firefox.find_element_by_id('class_sort').clear()
firefox.find_element_by_id('class_sort').send_keys('1')
#点击保存分类按钮
firefox.find_element_by_xpath("//button").click()
#添加检查点
try:
    firefox.find_element_by_xpath('//input[@value="1" and @class="span8"]').is_displayed()
except Exception as error:
    log = "dbshop_ST014 新增商品分类 执行失败"
    write_to_log(log)
    write_to_log(str(error))#调用函数写入日志
    assert False  # 手工设置一个报错信息
else:
    log = "dbshop_ST014 新增商品分类 执行成功"
    write_to_log(log)#调用函数写入日志、
time.sleep(4)
#获取文本框中的值,不能用text函数
value=firefox.find_element_by_xpath('//input[@value="1" and @class="span8"]').get_property("value")
print('第一行分类排序的值是',value)
firefox.quit()